FROM openjdk:8-jdk-alpine as builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
RUN java -Djarmode=layertools -jar app.jar extract

FROM openjdk:8-jdk-alpine
MAINTAINER qizai
ENV PARAMS=""
ENV JAVA_OPTS=""
ENV TIME_ZONE="Asia/Shanghai"
RUN ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo $TIME_ZONE > /etc/timezone && mkdir -p /www/web/logs
WORKDIR /www/web

COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./

RUN echo -e "#!/bin/sh \nnohup java \$JAVA_OPTS org.springframework.boot.loader.JarLauncher \$PARAMS > logs/start.out 2>&1 </dev/null" >> /www/web/docker-entrypoint.sh && chmod +x /www/web/docker-entrypoint.sh
ENTRYPOINT ["/www/web/docker-entrypoint.sh"]